https://www.nowcoder.com/practice/41c399fdb6004b31a6cbb047c641ed8a

typedef struct ListNode ListNode;
ListNode* BuyNode(int x)
{
    ListNode* tmp = (ListNode*)malloc(sizeof(ListNode));
    tmp->val = x;
    tmp->next = NULL;
    return tmp;

}
int ysf(int n, int m) {
    // write code here
    ListNode* phead, * ptail;
    ptail = phead = BuyNode(1);
    for (int i = 2;i <= n;i++)
    {
        ptail->next = BuyNode(i);
        ptail = ptail->next;
    }
    ptail->next = phead;
    ListNode* pcur = phead, * prev = NULL;
    int count = 1;
    while (pcur->next != pcur)
    {
        prev = pcur;
        pcur = pcur->next;
        count++;
        if (count == m)
        {
            prev->next = pcur->next;
            free(pcur);
            pcur = prev->next;
            count = 1;
        }

    }
    return pcur->val;



}